package com.zhongmai.yzfgrabanorder.view;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.TextView;

import com.zhongmai.yzfgrabanorder.R;

/**
 * 项目名称：YZFGrabAnOrder
 * 类描述：
 * 创建人：Administrator
 * 创建时间：2020/9/24 10:38
 * 修改人：Administrator
 * 修改时间：2020/9/24 10:38
 * 修改备注：
 */
public class LoadingDialog {
    String message = null;
    private Dialog dialog;
    private Context context;

    public LoadingDialog(Context context) {
        this.context = context;
    }

    public LoadingDialog(Context context, String message) {
        this.context = context;
        this.message = message;

    }

    public void show() {
        if (context == null) {
            return;
        }
        dialog = new Dialog(context, R.style.dialog);
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_loading, null, false);
        TextView text_loading = (TextView) view.findViewById(R.id.text_loading);
        dialog.setContentView(view);
        dialog.show();
        //        if(!StringUtils.isBlank(message)){
        //            text_loading.setText(message);
        //        }
        WindowManager.LayoutParams lp = dialog.getWindow().getAttributes();
        lp.width = ViewGroup.LayoutParams.WRAP_CONTENT;
        lp.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        dialog.getWindow().setAttributes(lp);
        //设置点击屏幕不消失
        dialog.setCanceledOnTouchOutside(false);
        //设置点击返回键不消失
        dialog.setCancelable(false);
    }

    public void dismiss() {
        if (dialog != null && dialog.isShowing()) {
            dialog.dismiss();
        }
    }

    public boolean isShow() {
        return dialog.isShowing();
    }
}
